package com.quanquan.store.repository;

import com.quanquan.store.entity.CouponCommercial;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:CouponCommercialRepository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/6/24 8:50
 * @Version 1.0
 */
public interface CouponCommercialRepository extends JpaRepository<CouponCommercial, String> {


    /**
     * 通过券id查找对应的业态
     *
     * @param couponId
     * @return
     */
    @Query(value = "select * from oo_coupon_commercial where status_remove = 0 and coupon_id = ?1", nativeQuery = true)
    List<CouponCommercial> findByCouponIdAndStatus(String couponId);

    /**
     * 通过业态id查找对应的优惠券
     *
     * @param commercialId
     * @return
     */
    @Query(value = "select * from oo_coupon_commercial where status_remove = 0 and commercial_id = ?1", nativeQuery = true)
    List<CouponCommercial> findByCommercialIdAndStatus(String commercialId);

    /**
     * 通过券id和业态id查找
     *
     * @param couponId
     * @return
     */
    @Query(value = "select * from oo_coupon_commercial where status_remove = 0 and coupon_id = ?1 and commercial_id = ?1", nativeQuery = true)
    CouponCommercial findByCouponIdAndCommercialId(String couponId, String commercialId);
}
